using UnityEngine;

namespace Coffee.UIExtensions
{
    // [Assembly-CSharp.dll].Coffee.UIExtensions.MaterialCache
    public class MaterialCache
    {
        
        #region Coffee.UIExtensions.MaterialCache.<>c__DisplayClass17_0
        // [Assembly-CSharp.dll].Coffee.UIExtensions.MaterialCache.<>c__DisplayClass17_0
        private sealed class __c__DisplayClass17_0
        {
            // Fields
            public ulong hash;
            
            // Methods
            public __c__DisplayClass17_0()
            {
            
            }
            internal bool <Register>b__0(Coffee.UIExtensions.MaterialCache x)
            {
                return (bool)(x._hash_k__BackingField == this.hash) ? 1 : 0;
            }
        
        }
        
        #endregion
        
        
        #region Coffee.UIExtensions.MaterialCache.<>c__DisplayClass18_0
        // [Assembly-CSharp.dll].Coffee.UIExtensions.MaterialCache.<>c__DisplayClass18_0
        private sealed class __c__DisplayClass18_0
        {
            // Fields
            public ulong hash;
            
            // Methods
            public __c__DisplayClass18_0()
            {
            
            }
            internal bool <Register>b__0(Coffee.UIExtensions.MaterialCache x)
            {
                return (bool)(x._hash_k__BackingField == this.hash) ? 1 : 0;
            }
        
        }
        
        #endregion
        
        // Fields
        private ulong _hash_k__BackingField;
        private int _referenceCount_k__BackingField;
        private UnityEngine.Texture _texture_k__BackingField;
        private UnityEngine.Material _material_k__BackingField;
        public static System.Collections.Generic.List<Coffee.UIExtensions.MaterialCache> materialCaches;
        
        // Properties
        public ulong hash { get; set; }
        public int referenceCount { get; set; }
        public UnityEngine.Texture texture { get; set; }
        public UnityEngine.Material material { get; set; }
        
        // Methods
        public ulong get_hash()
        {
            return (ulong)this._hash_k__BackingField;
        }
        private void set_hash(ulong value)
        {
            this._hash_k__BackingField = value;
        }
        public int get_referenceCount()
        {
            return (int)this._referenceCount_k__BackingField;
        }
        private void set_referenceCount(int value)
        {
            this._referenceCount_k__BackingField = value;
        }
        public UnityEngine.Texture get_texture()
        {
            return (UnityEngine.Texture)this._texture_k__BackingField;
        }
        private void set_texture(UnityEngine.Texture value)
        {
            this._texture_k__BackingField = value;
        }
        public UnityEngine.Material get_material()
        {
            return (UnityEngine.Material)this._material_k__BackingField;
        }
        private void set_material(UnityEngine.Material value)
        {
            this._material_k__BackingField = value;
        }
        public static Coffee.UIExtensions.MaterialCache Register(ulong hash, UnityEngine.Texture texture, System.Func<UnityEngine.Material> onCreateMaterial)
        {
            var val_9;
            System.Func<Unknown, System.Boolean> val_10;
            object val_11;
            var val_12;
            var val_13;
            object val_1 = 536899325;
            val_1 = new System.Object();
            mem[536899341] = hash;
            val_9 = 536889331;
            if(mem[536889555] == 0)
            {
                    val_9 = 536889331;
            }
            
            System.Func<System.Object, System.Boolean> val_2 = 536903161;
            val_10 = val_2;
            val_2 = new System.Func<System.Object, System.Boolean>(object:  val_1, method:  1610678777);
            Unknown val_3 = System.Linq.Enumerable.FirstOrDefault<System.Object>(source:  mem[536889515], predicate:  val_10);
            if(val_3 != 0)
            {
                    val_11 = val_3;
                val_10 = mem[val_3 + 40];
                val_10 = val_3 + 40;
                if((UnityEngine.Object.op_Implicit(exists:  val_10)) == false)
            {
                    return (Coffee.UIExtensions.MaterialCache)val_11;
            }
            
                val_10 = mem[val_3 + 40];
                val_10 = val_3 + 40;
                if((UnityEngine.Object.op_Implicit(exists:  val_10)) != false)
            {
                    var val_9 = val_3 + 24;
                val_9 = val_9 + 1;
                mem2[0] = val_9;
                return (Coffee.UIExtensions.MaterialCache)val_11;
            }
            
                val_12 = 536889331;
                if(mem[536889555] == 0)
            {
                    val_12 = 536889331;
            }
            
                bool val_6 = mem[536889515].Remove(item:  val_11);
            }
            
            object val_7 = 536889331;
            val_11 = val_7;
            val_7 = new System.Object();
            mem[536889347] = mem[536899341];
            mem[536889371] = val_7;
            mem[536889355] = 1;
            val_13 = 536889331;
            if(mem[536889555] == 0)
            {
                    val_13 = 536889331;
            }
            
            var val_10 = mem[536889515] + 28;
            var val_11 = mem[536889515] + 16;
            val_10 = val_10 + 1;
            mem2[0] = val_10;
            if((mem[536889515] + 24) >= (mem[536889515] + 16 + 24))
            {
                    return (Coffee.UIExtensions.MaterialCache)val_11;
            }
            
            val_11 = val_11 + ((mem[536889515] + 24) << 3);
            mem2[0] = (mem[536889515] + 24) + 1;
            mem2[0] = val_11;
            return (Coffee.UIExtensions.MaterialCache)val_11;
        }
        public static Coffee.UIExtensions.MaterialCache Register(ulong hash, System.Func<UnityEngine.Material> onCreateMaterial)
        {
            var val_6;
            var val_7;
            var val_8;
            object val_1 = 536899327;
            val_1 = new System.Object();
            mem[536899343] = hash;
            val_6 = 536889331;
            if(mem[536889555] == 0)
            {
                    val_6 = 536889331;
            }
            
            System.Func<System.Object, System.Boolean> val_2 = 536903161;
            val_2 = new System.Func<System.Object, System.Boolean>(object:  val_1, method:  1610678781);
            Unknown val_3 = System.Linq.Enumerable.FirstOrDefault<System.Object>(source:  mem[536889515], predicate:  val_2);
            if(val_3 != 0)
            {
                    var val_6 = val_3 + 24;
                val_7 = val_3;
                val_6 = val_6 + 1;
                mem2[0] = val_6;
                return (Coffee.UIExtensions.MaterialCache)val_7;
            }
            
            object val_4 = 536889331;
            val_7 = val_4;
            val_4 = new System.Object();
            mem[536889347] = mem[536899343];
            mem[536889371] = val_4;
            mem[536889355] = 1;
            val_8 = 536889331;
            if(mem[536889555] == 0)
            {
                    val_8 = 536889331;
            }
            
            var val_7 = mem[536889515] + 28;
            var val_8 = mem[536889515] + 16;
            val_7 = val_7 + 1;
            mem2[0] = val_7;
            if((mem[536889515] + 24) >= (mem[536889515] + 16 + 24))
            {
                    return (Coffee.UIExtensions.MaterialCache)val_7;
            }
            
            val_8 = val_8 + ((mem[536889515] + 24) << 3);
            mem2[0] = (mem[536889515] + 24) + 1;
            mem2[0] = val_7;
            return (Coffee.UIExtensions.MaterialCache)val_7;
        }
        public static void Unregister(Coffee.UIExtensions.MaterialCache cache)
        {
            var val_2;
            if(cache == null)
            {
                    return;
            }
            
            int val_2 = cache._referenceCount_k__BackingField;
            val_2 = val_2 - 1;
            cache._referenceCount_k__BackingField = val_2;
            if(val_2 > 0)
            {
                    return;
            }
            
            val_2 = 536889331;
            if(mem[536889555] == 0)
            {
                    val_2 = 536889331;
            }
            
            bool val_1 = mem[536889515].Remove(item:  cache);
            cache._material_k__BackingField = 0;
            throw new NullReferenceException();
        }
        public MaterialCache()
        {
        
        }
        private static MaterialCache()
        {
            System.Collections.Generic.List<System.Object> val_1 = 536903737;
            val_1 = new System.Collections.Generic.List<System.Object>();
            mem2[0] = val_1;
            throw new NullReferenceException();
        }
    
    }

}
